﻿// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)

Shader "Sprites/Default"
{
	Properties
	{
		_MainTex("Sprite Texture", 2D) = "white" {}
		_Color("Tint", Color) = (1,1,1,1)
	}

		SubShader
		{
			Tags
			{
				"Queue" = "Transparent"
				"IgnoreProjector" = "True"
				"RenderType" = "Transparent"
				"PreviewType" = "Plane"
				"CanUseSpriteAtlas" = "True"
			}

			Cull Off
			Lighting Off
			ZWrite Off
			Blend SrcAlpha OneMinusSrcAlpha

			Pass
			{
			HLSLPROGRAM
				#pragma prefer_hlslcc gles
				#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

				#pragma vertex VShader
				#pragma fragment FShader
					sampler2D _MainTex;
					float4 _Flip[10];

				CBUFFER_START(UnityPerMaterial)
					float4 _MainTex_ST;
					float4 _Color;
				CBUFFER_END

				struct VertexInput {
						float3 position : POSITION;
						float2 texCoord : TEXCOORD0;
						float4 color : COLOR;
					};

					struct VertexOutput {
						float4 position : SV_POSITION;
						float2 texCoord : TEXCOORD0;
						float4 color : COLOR;
					};

					VertexOutput VShader(VertexInput v) {

						float3 posWS = TransformObjectToWorld(v.position);
						float4 position = TransformWorldToHClip(posWS);
						//v.texCoord *= 1.5;
						VertexOutput o = {
							position,
							TRANSFORM_TEX(v.texCoord, _MainTex),
							v.color,
						};

						return o;
					}
					half4 GetColor(half4 color1, half4 color2)
					{
						return color2 * color2.a + (color1 * color1.a) * (1 - color2.a);
					}


					half4 FShader(VertexOutput v) : SV_Target{
						half4 color1 =  tex2D(_MainTex, v.texCoord - _Flip[0].xy);
						half4 color2 =  tex2D(_MainTex, v.texCoord - _Flip[1].xy);
						half4 color3 =  tex2D(_MainTex, v.texCoord - _Flip[2].xy);
						half4 color4 =  tex2D(_MainTex, v.texCoord - _Flip[3].xy);
						half4 color5 =  tex2D(_MainTex, v.texCoord);
						half4 color6 =  tex2D(_MainTex, v.texCoord);
						half4 col = GetColor(color1, color2);
						col = GetColor(col, color3);
						col = GetColor(col, color4);
						color1.rgb *= color1.a;
						return col;
					}
			ENDHLSL
			}
		}
}
